package com.ysucode.controller.user;

import com.ysucode.utils.CheckCodeUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class CheckCodeController {

    @RequestMapping("/checkCodeServlet")
    public void getCheckCodeRegister(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //获取response字节输出流os
        ServletOutputStream os = response.getOutputStream();
        //获取session对象 这步要放在产生验证码之前 要不然图片显示不出来
        HttpSession session = request.getSession();
        //调用util工具类产生验证码
        String checkCode = CheckCodeUtil.outputVerifyImage(97, 40, os, 4);
        //设置session
        session.setAttribute("checkcodegen", checkCode);

        //System.out.println("register code:" + checkCode);
    }
}
